<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link href="../static/mui/css/mui.min.css" rel="stylesheet"/>
    <style type="text/css">
    	body{
    		margin: 0%;
    	}
    	.mui-input-group{
    		margin-bottom: 6%;
    	}
    	.mui-input-group .mui-input-row{
    		height: 60px;
    	}
    	.mui-input-row input{
    		height: 70px;
    	}
    	.checkbox{
    		height: 60px; 
    		line-height: 60px;
    	}
    	.mui-checkbox.mui-left{
    		display: inline-block;
    	}
    	input[name='checkbox']{
    		height: 60px; 
    		line-height: 60px;
    	}
    	.mui-content-padded{
    		margin-top: 6%;
    		margin-bottom: 6%;
    	}
    	.serTel{
		    margin-top: 77%;
		    font-size: 16px;
		    color: #999999;
    	}
    	.mui-input-row .mui-input-clear~.mui-icon-clear{
			font-size: 20px;
			position: absolute;
			z-index: 1;
			top: 20px;
			right: 0;
			width: 38px;
			height: 38px;
			text-align: center;
			color: #999;
		}
		.mui-btn-block {
		    padding:9px 0;
		}
    </style>
</head>
<body>
	<!--标题-->
	<header class="mui-bar mui-bar-nav" style="background-color:#DD524D; ">
	    <h1 class="mui-title" style="color:#FFFFFF" >登录</h1>
	</header>
	<!--内容-->
	<div class="mui-content">
		<!--表单提交数据-->
	    <form class="mui-input-group">
	        <div class="mui-input-row">
	            <input type="text" id="accountInpt" class="mui-input-clear" placeholder="手机号">
	        </div>
	        <div class="mui-input-row">
	            <input type="password" id="pwdInpt" class="mui-input-clear" placeholder="密码">
	        </div>
	        <div class="mui-input-row checkbox" style="display: none;">
	            <div class="mui-checkbox mui-left" >
	            	<label >记住账号</label>
	            	<input name="checkbox" type="checkbox" id="isRememberMeChk" checked>
	            </div>
	            <div class="mui-checkbox mui-left" style="float: right; display:none;">
	             	<label>自动登录</label>
	            	<input name="checkbox" type="checkbox" id="isAutoLoginChk">
	            </div>
	        </div>
	    </form>
		 <!--登录-->
	    <div class="mui-content-padded" >
			<button id="doLoginBtn" type="button" class="mui-btn mui-btn-block mui-btn-primary">登录</button>
		</div>
		<!--忘记密码-->
		<div class="mui-text-right" style="display: block;"><span style="padding-right: 10px;" id="forgetPwd" >忘记密码？</span></div>
		<!--服务电话-->
		<div class="mui-text-center serTel"  ><span>服务电话 </span><span>0371-86563519</span></div>
	</div>
	<script type="text/javascript" src="../static/lib/jquery-1.11.2.min.js"></script>
	<script type="text/javascript" src="../static/mui/js/mui.min.js"></script>
	<script type="text/javascript" src="../static/app/js/kit.js"></script>
	<script type="text/javascript" src="../static/app/js/api.js"></script>
	<script type="text/javascript" src="../static/app/js/prop.js"></script>
	<script type="text/javascript" charset="utf-8">
		mui.init({
			preloadPages:[ 
			    {
			      url:'order/cancel.html',
			      id:'views/order/cancel.html'
			    },
			     {
			      url:'order/finish.html',
			      id:'views/order/finish.html'
			    },
			     {
			      url:'order/wait.html',
			      id:'views/order/wait.html'
			    }
			     
			  ]
		});
		mui.plusReady(function () {
			//执行版本检查
	      	API.checkVersion(true);
			//开始创建底部菜单页面webview
			var indexWebView = plus.webview.create("index.html","index.html");
			setTimeout(function(){mui.fire(indexWebView,"indexwebview");},2000);
			$("#doLoginBtn").on("tap",function(){
				Kit.ui.showLoading();
				var account = $("#accountInpt").val();
				var pwd = $("#pwdInpt").val();
				if(Kit.validate.isBlank(account)){
					Kit.ui.alert("请输入手机号");
					Kit.ui.closeLoading();
					return;
				}else if(Kit.validate.isBlank(pwd)){
					Kit.ui.alert("请输入密码");
					Kit.ui.closeLoading();
					return;
				}else{
					doLogin(account,pwd);
				}
			});
			
			function doLogin(account,pwd){
				if(plus.networkinfo.getCurrentType()==1||plus.networkinfo.getCurrentType()==0){
					Kit.ui.alert("当前网络不可用"); 
				}
				API.doLogin(account,pwd,function(obj){
					var shop = obj.SHOP;
					//缓存用户信息
					Kit.dao.save("account",account);
					Kit.dao.save("pwd",pwd);
					Kit.dao.save("SHOP",shop,true);
					
					//获取并注册个推clientid
					var info = plus.push.getClientInfo();
 					API.registerDevice(shop.ID, info.clientid, plus.device.uuid,function(obj){
 						var orderIndex = plus.webview.getWebviewById("order/indexList.html");
 						mui.fire(orderIndex,"getOrderIndexData",{shopid:shop.ID});
						//1秒后打开避免了页面显示空白 
						setTimeout(function(){
							mui.openWindow({
								id:'index.html',
								show:{duration:200},//页面动画持续时间2毫秒
							});
							Kit.ui.closeLoading();
						},1000);
 					});
				},function(flag,msg,object){
					Kit.ui.alert(msg);
					Kit.ui.closeLoading();
				});
			}
			//忘记密码
			document.getElementById("forgetPwd").addEventListener("tap",function(){
				mui.openWindow({
					url:"common/findPwd.html"
				});
			});
			//绑定后退操作时提示是否退出应用
	       mui.back = function() {
	            Kit.ui.confirm(Prop.appName,"确定要退出应用？",function(e) {
                    plus.runtime.quit();
	            });
	        }
		});
    </script>
</body>
</html>